<template>
    <div id="app">
        <input type="text" v-model="username" />
        <input type="text" v-model="password" />
        <button @click="login">登录</button>
    </div>
</template>

<script>
// axios 封装
export default {
    data() {
        return {
            username: '',
            password: '',
        }
    },
    methods: {
        login() {
            // 派发vuex中的登录接口
            this.$store.dispatch('user/LOGIN', {
                username: this.username,
                password: this.password
            }).then(res => {
                if (res.success) {
                    // 跳转页面
                    this.$router.push('/dashboard').catch(() => {
                        //捕获报错
                    })
                }
            })
        }
    }
}
</script>

<style>
</style>